package com.aaa.PController;

import com.aaa.Entity.Menu;
import com.aaa.Entity.User;
import com.aaa.Service.MenuService;
import com.aaa.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private MenuService menuService;


    @RequestMapping("/toLogin")
    private String toLogin(){
        return "login";
    }

    @RequestMapping("/welcome")
    private String welcome(){
        return "welcome";
    }



    //校验用户名和密码是否正确
    @RequestMapping("/checkUser")
    private String checkUser(User user,Model model){
        User uAndP = userService.findUAndP(user);
        if(uAndP==null){
            return "error";

        }else {
            //获取用户id，根据用户id  查询用户操作的所有菜单
            List<Menu> menus = menuService.listMyMenu(uAndP.getId());
            //吧menus传递到jsp界面
            model.addAttribute("menus",menus);
            return "Index";
        }
    }

}
